<template>
  <el-dialog v-model="visible" title="添加活动" :before-close="cancel">
    <el-form :model="form" label-width="80px">
      <el-form-item label="活动标题:">
        <el-input v-model="form.title" />
      </el-form-item>
      <el-form-item label="开始时间:">
        <el-date-picker v-model="form.startDate" type="date" placeholder="请选择时间" />
      </el-form-item>
      <el-form-item label="结束时间:">
        <el-date-picker v-model="form.endDate" type="date" placeholder="请选择时间" />
      </el-form-item>
      <el-form-item label="上线/下线">
        <el-radio-group v-model="form.status" class="ml-4">
          <el-radio :label="1" size="large">上线</el-radio>
          <el-radio :label="0" size="large">下线</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="flashCreateFn">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref } from "vue";
import * as http from "@/request/api";

const props = withDefaults(defineProps<{ visible: boolean }>(), {
  visible: false,
});

const form = reactive({
  endDate: "",
  startDate: "",
  status: 0,
  title: "",
});
// 声明emit
const emit = defineEmits<{
  (event: "close"): void;
}>();

// 关闭方法
function cancel() {
  emit("close");
}

// 点击确定添加
async function flashCreateFn() {
  //   console.log(form);
  await http.flash.FlashCreate(form);
  form.endDate = "";
  form.startDate = "";
  form.status = 0;
  form.title = "";
  emit("close");
}
</script>

<style>
.el-form {
  padding: 20px 100px;
}
</style>
